﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace UserCtrlProcess
{
    public partial class UsrCtrlProcs : UserControl
    {
        private Int32 procCount = 10;
        public Int32 ProcCount
        {
            set
            {
                if (value > 0 && value <= 10)
                {
                    procCount = value;
                    this.Initialize();
                    this.Refresh();
                }
            }
        }

        // 单个流程框的宽度
        private const Int32 width = 236;

        // 单个流程框的长度
        private const Int32 height = 101;

        // 流程框中用于输入的panel长度
        private const Int32 boxHeight = 69;
        private const Int32 arrowHeight = 33;
        private const Int32 marginLeft = 50;

        private const Int32 lineStart = 6;

        private Point startP;
        private Point endP;
        private List<Rectangle> procRect;
        private UsrCtrlProc usrCtrlProc;

        private List<UsrCtrlProc> usrCtrlProcs;

        private Int32 selectedProcIndex;

        private Pen pen;
        private Brush brush;

        public Boolean ValidateInputs
        {
            get
            {
                Boolean validate = true;
                if (usrCtrlProcs != null)
                {
                    foreach (var usrProc in usrCtrlProcs)
                    {
                        if (!usrProc.ValidateInput)
                        {
                            validate = false;
                            break;
                        }
                    }
                }
                return validate;
            }
        }

        public UsrCtrlProcs()
        {
            InitializeComponent();
            this.Height = height * 5 + boxHeight * 2 - arrowHeight;

            this.MouseUp += new MouseEventHandler(UsrCtrlProcs_MouseUp);

            pen = new Pen(Color.Black);
            brush = new SolidBrush(Color.Black);
        }

        public void Initialize()
        {
            this.Controls.Clear();
            this.InitProcCtrl();
        }

        private void UsrCtrlProcs_MouseUp(object sender, MouseEventArgs e)
        {


            if (startP.X == 0)
                return;
            if (Math.Abs(startP.X - endP.X) < 14)
                return;


            var direction = String.Empty;

            selectedProcIndex = 0;

            if ((startP.X > 227 && startP.X < 287) && (endP.X > 287) ||
                ((startP.X > 368 && startP.X < 478) && (endP.X < 368)))
            {
                foreach (var item in usrCtrlProcs)
                {
                    if (item == usrCtrlProc)
                        break;
                    selectedProcIndex++;
                }
                if (selectedProcIndex == procCount - 1)
                    return;

                direction = "Special";
            }
            else
            {
                if ((startP.X > 50 && startP.X < 60) || (startP.X > 368 && startP.X < 478))
                {
                    if (endP.Y - startP.Y < 78)
                        return;

                    direction = "Down";
                }

                else if ((startP.X > 277 && startP.X < 287) || (startP.X > 593 && startP.X < 603))
                {
                    if (startP.Y - endP.Y < 78)
                        return;

                    direction = "Up";
                }
            }
            produLine(direction);
        }

        private void InitProcCtrl()
        {
            var pnlBox = new Panel();
            pnlBox.Location = new Point(marginLeft + 18, 0);
            pnlBox.Size = new Size(200, boxHeight);
            pnlBox.BorderStyle = BorderStyle.FixedSingle;

            var lblFont = new Label();
            lblFont.Font = new Font("宋体", 20f, FontStyle.Bold);
            lblFont.AutoSize = true;
            lblFont.Text = "开始";
            lblFont.Location = new Point(pnlBox.Width / 2 - 25, boxHeight / 2 - 20);
            pnlBox.Controls.Add(lblFont);

            this.Controls.Add(pnlBox);

            var usrCtrlVer = new UsrCtrlVertPoly();
            usrCtrlVer.Location = new Point(marginLeft + 119, boxHeight);
            usrCtrlVer.Size = new Size(4, 33);
            this.Controls.Add(usrCtrlVer);

            var beginY = arrowHeight + boxHeight;

            procRect = new List<Rectangle>();
            usrCtrlProcs = new List<UsrCtrlProc>();

            UsrCtrlProc.arrowPst = "Down";
            var lfProcCount = procCount >= 5 ? 5 : procCount;
            var rhProcCount = procCount >= 5 ? procCount - 5 : 0;

            for (int index = 0; index < lfProcCount; index++)
            {
                var proc = new UsrCtrlProc();
                proc.Location = new Point(marginLeft, beginY + height * index);
                proc.MouseDown += new MouseEventHandler(triggerUsrCtrlMouseDown);
                proc.MouseUp += new MouseEventHandler(triggerUsrCtrlMouseUp);
                this.Controls.Add(proc);
                usrCtrlProcs.Add(proc);
                procRect.Add(new Rectangle(marginLeft, beginY + height * index, proc.Width - 5, proc.Height - arrowHeight));


            }

            ////UsrCtrlProc.arrowPst = "Up";
            for (int index = 0; index < rhProcCount; index++)
            {
                var proc = new UsrCtrlProc();
                proc.Location = new Point(marginLeft + width + 80, height * index);
                proc.MouseDown += new MouseEventHandler(triggerUsrCtrlMouseDown);
                proc.MouseUp += new MouseEventHandler(triggerUsrCtrlMouseUp);
                this.Controls.Add(proc);
                usrCtrlProcs.Add(proc);
                procRect.Add(new Rectangle(marginLeft + width + 80, height * index, proc.Width - 5, proc.Height - arrowHeight));
            }

            //usrCtrlVer = new UsrCtrlVertical();
            //usrCtrlVer.Location = new Point(marginLeft + width + 50 + 119, (boxHeight + 33) * procCount);
            //usrCtrlVer.Size = new Size(4, 33);
            //this.Controls.Add(usrCtrlVer);


            pnlBox = new Panel();

            if (rhProcCount >= 0 && lfProcCount == 5)
                pnlBox.Location = new Point(marginLeft + width + 100, (boxHeight + 33) * rhProcCount);
            else
                pnlBox.Location = new Point(marginLeft + 18, (boxHeight + 33) * (lfProcCount + 1));

            pnlBox.Size = new Size(200, boxHeight);
            pnlBox.BorderStyle = BorderStyle.FixedSingle;

            lblFont = new Label();
            lblFont.Font = new Font("宋体", 20f, FontStyle.Bold);
            lblFont.AutoSize = true;
            lblFont.Text = "结束";
            lblFont.Location = new Point(pnlBox.Width / 2 - 25, boxHeight / 2 - 20);
            pnlBox.Controls.Add(lblFont);

            this.Controls.Add(pnlBox);
        }

        private void triggerUsrCtrlMouseUp(Object sender, MouseEventArgs e)
        {
            var ctrlProc = (UsrCtrlProc)sender;
            if (ctrlProc != null && ctrlProc.drowLine)
            {
                endP = new Point(Cursor.Position.X, Cursor.Position.Y);
                endP = this.PointToClient(endP);
            }
            this.OnMouseUp(e);
        }

        private void triggerUsrCtrlMouseDown(Object sender, MouseEventArgs e)
        {
            var ctrlProc = (UsrCtrlProc)sender;
            if (ctrlProc != null && ctrlProc.drowLine)
            {
                usrCtrlProc = ctrlProc;
                startP = new Point(Cursor.Position.X, Cursor.Position.Y);
                startP = this.PointToClient(startP);
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (usrCtrlProcs != null)
            {
                foreach (var usrProc in usrCtrlProcs)
                {
                    if (usrProc.lineClass != null)
                    {
                        e.Graphics.DrawLine(pen, usrProc.lineClass.startP, usrProc.lineClass.endP);
                        e.Graphics.DrawPolygon(pen, usrProc.lineClass.ptf);
                        e.Graphics.FillPolygon(brush, usrProc.lineClass.ptf);
                    }
                }
            }

            //if (procRect != null)
            //{
            //    foreach (var item in procRect)
            //    {
            //        e.Graphics.DrawRectangle(pen, item);
            //    }
            //}
        }

        private void produLine(String direction)
        {
            var endRect = new Rectangle(endP.X, endP.Y, 10, 10);
            UsrCtrlLine[] usrCtrlLines;
            for (int index = 0; index < procRect.Count; index++)
            {
                // usrCtrlProcs[index].Visible = false;

                if (procRect[index].IntersectsWith(endRect))
                {

                    usrCtrlLines = new UsrCtrlLine[3];
                    Int32 locaX = 0;
                    Int32 locaY = 0;
                    Int32 startCount = index % 5;
                    Int32 horiWidth = 33 - lineStart * startCount;

                    var arrowPoint = usrCtrlProcs[index].GetPnlPoint();

                    if (direction == "Special")
                    {
                        PointF[] ptf;

                        locaY = arrowPoint.Y + usrCtrlProcs[index].Top;
                        if (startP.X > endP.X)
                        {
                            locaX = arrowPoint.X + usrCtrlProcs[index].Right;
                            ptf = new PointF[3]{
                                new PointF(locaX,locaY),
                                new PointF(locaX + 8,locaY-2),
                                new PointF(locaX+2,locaY -8)
                            };
                        }
                        else
                        {
                            locaX = arrowPoint.X + usrCtrlProcs[index].Left;
                            ptf = new PointF[3]{
                                new PointF(locaX,locaY),
                                new PointF(locaX-8,locaY+2),
                                new PointF(locaX-2,locaY+8)
                            };
                        }


                        var lineClass = new LineClass
                        {
                            startP = startP,
                            endP = new Point(locaX, locaY),
                            ptf = ptf
                        };

                        usrCtrlProc.lineClass = lineClass;

                        if (usrCtrlProc.usrCtrlLines.ContainsKey(lineClass.PointPos))
                        {
                            foreach (var line in usrCtrlProc.usrCtrlLines[lineClass.PointPos])
                            {
                                this.Controls.Remove(line);
                            }
                        }
                        if (selectedProcIndex != 4)
                            usrCtrlProc.RemoveDefArrow();
                    }
                    else
                    {

                        if (usrCtrlProc.usrCtrlLines.ContainsKey(direction))
                        {
                            foreach (var line in usrCtrlProc.usrCtrlLines[direction])
                            {
                                this.Controls.Remove(line);
                            }
                        }

                        usrCtrlLines[0] = new UsrCtrlHoriPoly();
                        usrCtrlLines[1] = new UsrCtrlHorizen();
                        usrCtrlLines[2] = new UsrCtrlLine();
                        usrCtrlProc.usrCtrlLines[direction] = usrCtrlLines;

                        Boolean speDown = false;
                        if (direction == "Down")
                        {
                            UsrCtrlHoriPoly.Direction = "Right";
                            locaX = arrowPoint.X + usrCtrlProcs[index].Left - horiWidth;
                            locaY = arrowPoint.Y + usrCtrlProcs[index].Top;
                            usrCtrlLines[2].Location = new Point(locaX - 2, startP.Y);

                            if ((locaY - startP.Y + 2) < (height + boxHeight))
                            {
                                speDown = true;
                                usrCtrlProc.AddDefArrow();
                            }
                            else
                            {
                                speDown = false;
                                usrCtrlProc.RemoveDefArrow();
                            }
                        }
                        else if (direction == "Up")
                        {
                            UsrCtrlHoriPoly.Direction = "Left";
                            locaX = arrowPoint.X + usrCtrlProcs[index].Left + usrCtrlProcs[index].Width;
                            locaY = arrowPoint.Y + usrCtrlProcs[index].Top;

                            usrCtrlLines[2].Location = new Point(locaX - 2 + horiWidth, startP.Y - Math.Abs(locaY - startP.Y + 2));
                        }

                        if (!speDown)
                        {
                            if (locaX <= 0) return;
                            usrCtrlLines[1].Width = horiWidth;
                            usrCtrlLines[1].Location = new Point(locaX, startP.Y - 2);
                            usrCtrlLines[1].Height = 4;
                            usrCtrlLines[2].Height = Math.Abs(locaY - startP.Y + 2);
                            usrCtrlLines[2].Width = 4;
                            usrCtrlLines[0].Width = horiWidth;
                            usrCtrlLines[0].Location = new Point(locaX, locaY);

                            foreach (var line in usrCtrlLines)
                            {
                                this.Controls.Add(line);
                            }
                        }

                        if (usrCtrlProc.lineClass != null && usrCtrlProc.lineClass.PointPos == direction)
                        {
                            usrCtrlProc.lineClass = null;
                        }

                    }


                }
            }

            this.Refresh();
            startP.X = 0;
            startP.Y = 0;
        }
    }

    public partial class UsrCtrlProc : UserControl
    {

        private System.Windows.Forms.Panel pnlProcBox;
        private System.Windows.Forms.Label lblTarName;
        private System.Windows.Forms.TextBox txtProcName;
        private System.Windows.Forms.Label lblProcName;
        private System.Windows.Forms.TextBox txtTarName;
        private UsrCtrlVertPoly usrCtrlVertical1;
        private System.Windows.Forms.Panel pnlLeft;
        private System.Windows.Forms.Panel pnlRight;



        public static String arrowPst = "Down";

        public UsrCtrlLine[] usrCtrlLeftLines;
        public UsrCtrlLine[] usrCtrlRightLines;

        public Dictionary<String, UsrCtrlLine[]> usrCtrlLines;

        public Boolean drowLine;

        private LineClass lneClass;
        public LineClass lineClass { get; set; }

        public Boolean ValidateInput
        {
            get { return !String.IsNullOrEmpty(this.txtProcName.Text.Trim()) && !String.IsNullOrEmpty(this.txtTarName.Text.Trim()); }
        }

        public UsrCtrlProc()
        {
            InitializeComponent();

            if (arrowPst == "Up")
            {
                this.usrCtrlVertical1.Location = new Point(this.usrCtrlVertical1.Location.X, 0);

                this.pnlLeft.Location = new Point(this.pnlLeft.Location.X, this.pnlLeft.Location.Y + this.usrCtrlVertical1.Height);
                this.pnlRight.Location = new Point(this.pnlRight.Location.X, this.pnlRight.Location.Y + this.usrCtrlVertical1.Height);
                this.pnlProcBox.Location = new Point(this.pnlProcBox.Location.X, this.pnlProcBox.Location.Y + this.usrCtrlVertical1.Height);
            }

            this.pnlLeft.MouseDown += new MouseEventHandler(mouseDownCoor);
            this.pnlRight.MouseDown += new MouseEventHandler(mouseDownCoor);

            this.pnlRight.MouseUp += new MouseEventHandler(mouseUpCoor);
            this.pnlLeft.MouseUp += new MouseEventHandler(mouseUpCoor);

            usrCtrlLeftLines = new UsrCtrlLine[3];
            usrCtrlRightLines = new UsrCtrlLine[3];

            usrCtrlLines = new Dictionary<string, UsrCtrlLine[]>();
        }



        public Point GetPnlPoint()
        {
            var arrowPoint = new Point(this.pnlLeft.Location.X, this.pnlLeft.Location.Y);
            return arrowPoint;
        }

        public void AddDefArrow()
        {
            this.usrCtrlVertical1.Visible = true;
        }

        public void RemoveDefArrow()
        {
            this.usrCtrlVertical1.Visible = false;
        }

        private void mouseDownCoor(object sender, MouseEventArgs e)
        {
            drowLine = true;
            this.OnMouseDown(e);
        }

        private void mouseUpCoor(Object sender, MouseEventArgs e)
        {
            this.OnMouseUp(e);
        }

        private void InitializeComponent()
        {
            this.pnlProcBox = new System.Windows.Forms.Panel();
            this.txtTarName = new System.Windows.Forms.TextBox();
            this.lblTarName = new System.Windows.Forms.Label();
            this.txtProcName = new System.Windows.Forms.TextBox();
            this.lblProcName = new System.Windows.Forms.Label();
            this.pnlLeft = new System.Windows.Forms.Panel();
            this.pnlRight = new System.Windows.Forms.Panel();
            this.usrCtrlVertical1 = new UserCtrlProcess.UsrCtrlVertPoly();
            this.pnlProcBox.SuspendLayout();
            this.SuspendLayout();
            // 
            // pnlProcBox
            // 
            this.pnlProcBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.pnlProcBox.Controls.Add(this.txtTarName);
            this.pnlProcBox.Controls.Add(this.lblTarName);
            this.pnlProcBox.Controls.Add(this.txtProcName);
            this.pnlProcBox.Controls.Add(this.lblProcName);
            this.pnlProcBox.Location = new System.Drawing.Point(6, 1);
            this.pnlProcBox.Name = "pnlProcBox";
            this.pnlProcBox.Size = new System.Drawing.Size(226, 68);
            this.pnlProcBox.TabIndex = 0;
            // 
            // txtTarName
            // 
            this.txtTarName.Location = new System.Drawing.Point(65, 38);
            this.txtTarName.Name = "txtTarName";
            this.txtTarName.Size = new System.Drawing.Size(141, 21);
            this.txtTarName.TabIndex = 3;
            // 
            // lblTarName
            // 
            this.lblTarName.AutoSize = true;
            this.lblTarName.Location = new System.Drawing.Point(12, 41);
            this.lblTarName.Name = "lblTarName";
            this.lblTarName.Size = new System.Drawing.Size(47, 12);
            this.lblTarName.TabIndex = 2;
            this.lblTarName.Text = "指定人:";
            // 
            // txtProcName
            // 
            this.txtProcName.Location = new System.Drawing.Point(65, 11);
            this.txtProcName.Name = "txtProcName";
            this.txtProcName.Size = new System.Drawing.Size(141, 21);
            this.txtProcName.TabIndex = 1;
            // 
            // lblProcName
            // 
            this.lblProcName.AutoSize = true;
            this.lblProcName.Location = new System.Drawing.Point(12, 14);
            this.lblProcName.Name = "lblProcName";
            this.lblProcName.Size = new System.Drawing.Size(47, 12);
            this.lblProcName.TabIndex = 0;
            this.lblProcName.Text = "流程名:";
            // 
            // pnlLeft
            // 
            this.pnlLeft.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.pnlLeft.Cursor = System.Windows.Forms.Cursors.Hand;
            this.pnlLeft.Location = new System.Drawing.Point(1, 34);
            this.pnlLeft.Name = "pnlLeft";
            this.pnlLeft.Size = new System.Drawing.Size(10, 10);
            this.pnlLeft.TabIndex = 2;
            // 
            // pnlRight
            // 
            this.pnlRight.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.pnlRight.Cursor = System.Windows.Forms.Cursors.Hand;
            this.pnlRight.Location = new System.Drawing.Point(226, 34);
            this.pnlRight.Name = "pnlRight";
            this.pnlRight.Size = new System.Drawing.Size(10, 10);
            this.pnlRight.TabIndex = 3;
            // 
            // usrCtrlVertical1
            // 
            this.usrCtrlVertical1.BackColor = System.Drawing.Color.Transparent;
            this.usrCtrlVertical1.Location = new System.Drawing.Point(119, 69);
            this.usrCtrlVertical1.Name = "usrCtrlVertical1";
            this.usrCtrlVertical1.Size = new System.Drawing.Size(4, 33);
            this.usrCtrlVertical1.TabIndex = 1;
            // 
            // UsrCtrlProc
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.pnlRight);
            this.Controls.Add(this.pnlLeft);
            this.Controls.Add(this.usrCtrlVertical1);
            this.Controls.Add(this.pnlProcBox);
            this.Name = "UsrCtrlProc";
            this.Size = new System.Drawing.Size(236, 102);
            this.pnlProcBox.ResumeLayout(false);
            this.pnlProcBox.PerformLayout();
            this.ResumeLayout(false);

        }

    }

    public partial class UsrCtrlLine : UserControl
    {
        private Color lineColor = Color.Black;
        protected PointF[] ptf;
        protected Pen pen;
        protected SolidBrush brush;
        protected String direction = "vertical";

        private Int32 width;
        private Int32 height;
        public new Int32 Width
        {
            get
            {
                return width;
            }
            set
            {
                this.width = value;
                base.Width = value;
            }
        }
        public new Int32 Height
        {
            get
            {
                return height;
            }
            set
            {
                this.height = value;
                base.Height = value;
            }
        }

        private const Int32 start = 2;

        private Point startP;
        private Point endP;

        public UsrCtrlLine()
        {
            SetStyle(
             ControlStyles.UserPaint |
             ControlStyles.AllPaintingInWmPaint |
             ControlStyles.OptimizedDoubleBuffer |
             ControlStyles.SupportsTransparentBackColor |
             ControlStyles.Selectable |
             ControlStyles.ResizeRedraw, true);
            this.BackColor = Color.Transparent;

            pen = new Pen(lineColor);
            brush = new SolidBrush(Color.Black);

            this.Width = base.Width;
            this.Height = base.Height;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.DrawLine(pen, startP, endP);
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            this.Width = base.Width;
            this.Height = base.Height;

            if (direction == "Down")
            {
                startP.X = 2;
                startP.Y = 2;

                endP.X = this.Width;
                endP.Y = this.Height;
            }
            else if (direction == "Up")
            {
                startP.X = 2;
                startP.Y = this.Height;

                endP.X = this.Width;
                endP.Y = 2;
            }
            else if (direction == "horizon")
            {
                startP.X = 0;
                startP.Y = 2;

                endP.X = this.width;
                endP.Y = 2;
            }
            else if (direction == "vertical")
            {
                startP.X = 2;
                startP.Y = 0;

                endP.X = 2;
                endP.Y = this.Height;
            }

        }
    }

    public partial class UsrCtrlLinePoly : UsrCtrlLine
    {
        public static String Direction = "Up";

        private Int32 width;
        private Int32 height;

        public Int32 Width
        {
            get { return width; }
            set
            {
                width = value;
                base.Width = value;
            }
        }
        public Int32 Height
        {
            get { return height; }
            set
            {
                height = value;
                base.Height = value;
            }
        }

        public UsrCtrlLinePoly()
        {
            SetStyle(
             ControlStyles.UserPaint |
             ControlStyles.AllPaintingInWmPaint |
             ControlStyles.OptimizedDoubleBuffer |
             ControlStyles.SupportsTransparentBackColor |
             ControlStyles.Selectable |
             ControlStyles.ResizeRedraw, true);
            this.BackColor = Color.Transparent;

            if (Direction.Contains("Up"))
                base.direction = "Up";
            else if (Direction.Contains("Down"))
                base.direction = "Down";
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.DrawPolygon(pen, ptf);
            e.Graphics.FillPolygon(brush, ptf);
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            if (Direction == "rightUp")
            {
                ptf = new PointF[3]{
                    new PointF(this.Width,0),
                    new PointF(this.Width - 4,0),
                    new PointF(this.Width,4)
                };
            }
            else if (Direction == "leftUp")
            {
                ptf = new PointF[3]{
                    new PointF(0,0),
                    new PointF(0,4),
                    new PointF(4,0)
                };
            }
            else if (Direction == "rightDown")
            {
                ptf = new PointF[3]{
                    new PointF(this.Width,this.Height),
                    new PointF(this.Width - 4,this.Height),
                    new PointF(this.Width,this.Height- 4)
                };
            }
            else if (Direction == "leftDown")
            {
                ptf = new PointF[3]{
                    new PointF(0,this.Height),
                    new PointF(0,this.Height -4),
                    new PointF(4,this.Height)
                };
            }
        }


    }

    public partial class UsrCtrlHoriPoly : UsrCtrlLine
    {
        public static String Direction = "Right";

        public UsrCtrlHoriPoly()
        {
            base.direction = "horizon";
            base.Height = 4;
            base.Width = 100;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.DrawPolygon(pen, ptf);
            e.Graphics.FillPolygon(brush, ptf);
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            if (Direction == "Right")
            {
                base.ptf = new PointF[3]{
                    new PointF(this.Width,this.Height-2),
                    new PointF(this.Width-8,this.Height-8),
                    new PointF(this.Width-8,this.Height)
                };
            }
            else if (Direction == "Left")
            {
                base.ptf = new PointF[3]{
                    new PointF(0,2),
                    new PointF(8,8),
                    new PointF(8,0)
                };
            }
        }
    }

    public partial class UsrCtrlVertPoly : UsrCtrlLine
    {
        public UsrCtrlVertPoly()
        {
            SetStyle(
             ControlStyles.UserPaint |
             ControlStyles.AllPaintingInWmPaint |
             ControlStyles.OptimizedDoubleBuffer |
             ControlStyles.SupportsTransparentBackColor |
             ControlStyles.Selectable |
             ControlStyles.ResizeRedraw, true);
            this.BackColor = Color.Transparent;
            base.Height = 100;
            base.Width = 4;

            base.direction = "vertical";
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.DrawPolygon(pen, ptf);
            e.Graphics.FillPolygon(brush, ptf);
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            base.ptf = new PointF[3]{
                    new PointF(this.Width-2,this.Height),
                    new PointF(this.Width-8,this.Height-8),
                    new PointF(this.Width,this.Height-8)
                };
        }
    }

    public partial class UsrCtrlHorizen : UsrCtrlLine
    {
        public UsrCtrlHorizen()
        {
            base.direction = "horizon";
        }
    }

    public partial class UsrCtrlVertical : UsrCtrlLine
    {
        public UsrCtrlVertical()
        {
            base.direction = "vertical";
        }
    }

    public class LineClass
    {
        public Point startP { get; set; }
        public Point endP { get; set; }
        public PointF[] ptf { get; set; }

        private String pointPos;
        public String PointPos
        {
            get
            {
                if (startP.Y > endP.Y)
                    pointPos = "Up";
                else
                    pointPos = "Down";
                return pointPos;
            }
        }

        public LineClass()
        {
            pointPos = String.Empty;
            ptf = new PointF[3];
        }

    }

}
